package org.example.mybatisdemo.mapper;

import org.apache.ibatis.annotations.*;
import org.example.mybatisdemo.model.UserInfo;

import java.util.List;

/**
 * 动态SQL练习
 */

@Mapper
public interface UserInfo2Mapper {

    @Insert("<script>" +
            "insert into userinfo (username, password, age," +
            "             <if test=\"gender!=null\">" +
            "                 gender," +
            "             </if>" +
            "             phone)" +
            "        values" +
            "            (#{username}, #{password}, #{age}," +
            "            <if test=\"gender!=null\">" +
            "                #{gender}," +
            "            </if>" +
            "             #{phone})" +
            "</script>")
    Integer insert(UserInfo userInfo);

    Integer insertByXML(UserInfo userInfo);


    /**
     * 使用where标签
     * @param userInfo
     * @return
     */
    List<UserInfo> selectByCondition(UserInfo userInfo);

    /**
     * 使用trim标签
     * @param userInfo
     * @return
     */
    List<UserInfo> selectByCondition2(UserInfo userInfo);

    /**
     * 使用trim标签
     * @param userInfo
     * @return
     */
    Integer updateByCondition(UserInfo userInfo);

    /**
     * 使用set标签
     * @param userInfo
     * @return
     */
    Integer updateByCondition2(UserInfo userInfo);

    /**
     * 使用foreach标签
     * @param ids
     * @return
     */
    Integer batchDelete(@Param("ids") List<Integer> ids);
}
